package com.gxl.butt.DAO.impl;

import com.gxl.butt.DAO.IbttokenDAO;
import com.gxl.butt.domain.BT_Token;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Created by GUOXIAOLIN on 2018/7/13.
 */
@Repository
public class BttokenDAOImpl extends HibernateBaseDao<BT_Token> implements IbttokenDAO {

    @Override
    public List<BT_Token> getTokenByUserId(Long userid) {

        String hql = "from "+ BT_Token.class.getName() + " do where  do.userid =  " + userid;
        List<BT_Token> bt_tokens = this.getListByHql(hql);
        if (bt_tokens != null && bt_tokens .size() > 0 ){
            return bt_tokens;
        }
        return null;
    }

    @Override
    public Long addToken(BT_Token bt_token) {

        return (Long) this.save(bt_token);
    }

    @Override
    public boolean updateToken(BT_Token bt_token) {
        this.update(bt_token);
        return true;

    }

    @Override
    public void delTokenByTokenId(Long tokenid) {

        this.delTokenByTokenId(tokenid);

    }

    @Override
    public List<BT_Token> getUseridByToken(String token) {
        String hql = "from "+ BT_Token.class.getName() + " do where do.token = '" + token +"'";
        System.out.println(hql);
        List<BT_Token> bt_tokens = this.getListByHql(hql);
        if (bt_tokens != null && bt_tokens .size() > 0 ){
            return bt_tokens;
        }
        return null;
    }

    @Override
    public List<BT_Token> getTokenByOpenid(String openid) {
        String hql = "from "+ BT_Token.class.getName() + " do where do.openid =  '" + openid + "'";
        List<BT_Token> bt_tokens = this.getListByHql(hql);
        if (bt_tokens != null && bt_tokens .size() > 0 ){
            return bt_tokens;
        }
        return null;
    }
}
